﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using Antu.Core.DataAccess;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_QPGJGInfoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        Label lbl项目名称, lbl征收范围;
        TextBox txt候选评估机构, txt概算评估机构;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            //if (HttpContext.Current.Session["UserID"] == null)
            //{
            //    Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            //}
            //else
            //{
            //    userid = HttpContext.Current.Session["UserID"].ToString();
            //}
            base.OnLoad(e);
            InitControl();
            Button btnHNull = (Button)FindControl("btnHNull");
            Button btnRNull = (Button)FindControl("btnRNull");
            Button BtnSave = (Button)FindControl("BtnSave");
            BtnSave.Click += new EventHandler(BtnSave_Click);
            btnHNull.Click += new EventHandler(btnHNull_Click);
            btnRNull.Click += new EventHandler(btnRNull_Click);
            string strpid = base.Page.Request["PID"];

            if (!base.Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(strpid))
                {
                    EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(strpid);
                    lbl项目名称.Text = project.项目名称;
                    lbl征收范围.Text = project.征收范围;
                    txt候选评估机构.Text = project.候选评估机构;
                    txt概算评估机构.Text = project.概算评估机构;
                    issq();
                }
            }
            IsLookPerson();
        }

        protected void issq()
        {
            string sql = "Select * From zs_project Where Id ='"+Page.Request["PId"]+"'";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count>0)
	        {
                if (dt.Rows[0]["部门申请状态"].ToString() == "0")
	            {
                    Button BtnSave = (Button)FindControl("BtnSave");
                    BtnSave.Enabled = false;
	            }
                
            }
        }

        private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '" + userid + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btnSave = (Button)FindControl("btnSave");
                        btnSave.Visible = false;
                    }
                }
            }
        }

        protected void InitControl()
        {
            lbl项目名称 = (Label)FindControl("lbl项目名称");
            lbl征收范围 = (Label)FindControl("lbl征收范围");
            txt候选评估机构 = (TextBox)FindControl("txt候选评估机构");
            txt概算评估机构 = (TextBox)FindControl("txt概算评估机构");
            
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            string strpid = base.Page.Request["PID"];

            EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(strpid);
            project.候选评估机构 = txt候选评估机构.Text;
            project.概算评估机构 = txt概算评估机构.Text;

            bool save = _EluZSDataProvider.SaveGSPGJG(strpid, project);
            if (save) { base.Page.Response.Write("<script>alert('保存成功！');window.location.href('ZS_QPGJGInfo.aspx?PID=" + strpid + "');</script>"); }
        }

        protected void btnRNull_Click(object sender, EventArgs e)
        {
            string strpid = base.Page.Request["PID"]; 
            _EluZSDataProvider.UpdatePGJGNull("zs_project", "概算评估机构", strpid);
            base.Page.Response.Write("<script>alert('清空成功！');window.location.href=window.location.href;</script>");
        }

        protected void btnHNull_Click(object sender, EventArgs e)
        {
            string strpid = base.Page.Request["PID"]; 
            _EluZSDataProvider.UpdatePGJGNull("zs_project", "候选评估机构", strpid);
            base.Page.Response.Write("<script>alert('清空成功！');window.location.href=window.location.href;</script>");
        }
    }
}


